package 力扣日常刷题.木22一月.第01天0108;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/1/8
 * @description
 */
public class Demo01格雷编码 {


    public List<Integer> grayCode(int n) {
        ArrayList<Integer> res = new ArrayList<>();
        res.add(0);

        if (n == 0) {
            return res;
        }

        int c = 1;
        while (c <= n) {
            int index = res.size()-1;

            while (index >= 0) {
                res.add(res.get(index--) + (int) Math.pow(2, c - 1));
            }
            c++;
        }
        return res;
    }
}
